package com.seo.proxy;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.log4j.Logger;

import com.seo.proxy.http.HttpRequest;

public class RequestLogger {

	private static final String SEPARATOR = "\n\n<------------------------------------------------------------------------------------------------->\n\n";

	private Logger LOGGER = Logger.getLogger(getClass());
	
	private BufferedWriter writer;

	public RequestLogger(File file) throws IOException {
		writer = new BufferedWriter(new FileWriter(file, true));
	}

	public void logRequest(HttpRequest httpRequest) {
		try {
			writer.write(httpRequest.getRawHeaders());
			if (httpRequest.getBody() != null) {
				writer.write(httpRequest.getBody());
			}
			writer.write(SEPARATOR);
			writer.flush();
		} catch (IOException e) {
			LOGGER.error(e.getMessage(), e);
		}
	}
}
